package aos.client.gui;

import thinlet.Slider;
import thinlet.event.Listener;


public class PadSliderCoordinator {
	
	private Slider horSlider;
	private Slider verSlider;
	public Pad pad;
	private Listener changeListener;
	
	
	public PadSliderCoordinator(Slider h, Slider v, Pad pad) {
		this.horSlider = h;
		h.addChangeListener(new Listener(this, "horizontalSliderChanged"));
		this.verSlider = v;
		v.addChangeListener(new Listener(this, "verticalSliderChanged"));
		this.pad = pad;
		pad.addChangeListener(new Listener(this, "padChanged"));
		this.horSlider.setValue(this.pad.getValueX());
		this.verSlider.setValue(this.pad.getValueY());
	}
	
	public void horizontalSliderChanged() {
		float value = horSlider.getValue();
		this.pad.setValues(value, pad.getValueY());
		Listener.invoke(changeListener);
	}
	
	public void verticalSliderChanged() {
		float value = verSlider.getValue();
		this.pad.setValues(pad.getValueX(), value);
		Listener.invoke(changeListener);
	}
	
	public void padChanged() {
		float valueX = pad.getValueX();
		float valueY = pad.getValueY();
		this.horSlider.setValue(valueX);
		this.verSlider.setValue(valueY);
		Listener.invoke(changeListener);
	}
	
	public void addChangeListener(Listener listener) {
		changeListener = Listener.add(changeListener, listener);
	}
	
	public void removeChangeListener(Listener listener) {
		changeListener = Listener.remove(changeListener, listener);
	}

}
